"""
des: 内建数据类型list
author: Mr_52Hz
date: 2020-06-01 4:22 PM
"""
from timeit import Timer


# 测试列表生成效率

def test_concat():
    ls = list()
    for i in range(10000):
        ls += [i]


def test_append():
    ls = list()
    for i in range(10000):
        ls.append(i)


def test_generate():
    ls = [i for i in range(10000)]


def test_list():
    ls = list(range(10000))


if __name__ == '__main__':
    print('run 10000 times spend time: ')
    t_concat = Timer('test_concat()', 'from __main__ import test_concat')
    print('list contact: %s' % t_concat.timeit(number=10000))
    t_append = Timer('test_append()', 'from __main__ import test_append')
    print('list append: %s' % t_append.timeit(number=10000))
    t_generate = Timer('test_generate()', 'from __main__ import test_generate')
    print('list generate: %s' % t_generate.timeit(number=10000))
    t_list = Timer('test_list()', 'from __main__ import test_list')
    print('list list: %s' % t_list.timeit(number=10000))

    # tips: concat > append > generate > list





